#include <windows.h>
#include "winTest.h"

#define MYCLASSNAME		"MyNotepad"

LRESULT CALLBACK wndproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpCmdLine, int nCmdShow)
{
	MSG msg;
	WNDCLASS	wndclass;

	wndclass.style=CS_HREDRAW|CS_VREDRAW;
	wndclass.lpfnWndProc=(WNDPROC)wndproc;
	wndclass.cbClsExtra=0;
	wndclass.cbWndExtra=0;
	wndclass.hInstance=hInstance;
	//wndclass.hIcon=LoadIcon(hInstance, "winmaintest.ICO");
	wndclass.hIcon=LoadIcon(hInstance, (LPCTSTR)IDR_MAINFRAME);
	wndclass.hCursor=LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground=(HBRUSH)(COLOR_WINDOW);
	wndclass.lpszMenuName=NULL;
	wndclass.lpszClassName=MYCLASSNAME;

	RegisterClass(&wndclass);

	HWND hwnd=CreateWindow(MYCLASSNAME, NULL, WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
		NULL, NULL, hInstance, NULL);

	if(!hwnd)
	{
		DWORD err=GetLastError();
		return -1;
	}

	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return msg.wParam;
}

LRESULT CALLBACK wndproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	}

	return 0;
}
